package com.example.homework09.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class MusicService2 extends Service {
    public MusicService2() {
    }
    private MusicHelper musicHelper = null;

    @Override
    public void onCreate() {
        Log.d("MusicService2------", "onCreate");
        super.onCreate();
        musicHelper = new MusicHelper(this);
    }

    @Override
    public void onDestroy() {
        Log.d("MusicService2------", "onDestroy");
        super.onDestroy();
//        musicHelper.destroy();
//        musicHelper=null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        musicHelper.play();
        Log.d("MusicService2------", "onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    public class MyBinder extends Binder {
        private MusicService2 service;
        public MyBinder(MusicService2 service) {
            this.service = service;
        }
        public void play(){service.musicHelper.play();}

        public void destroy(){service.musicHelper.destroy();}

        public void next(){service.musicHelper.next();}

        public void pause(){service.musicHelper.pause();}
    }


    @Override
    public IBinder onBind(Intent intent) {
        Log.d("MusicService2------", "onBind");
        return new MyBinder(this);
    }

}